class A(object):
    def __new__(cls, *args, **kwargs):
        print("A cls:", cls)
        print("A __new__ be called")
        instance=super().__new__(cls) # 产生
        print('A instance:', instance)
        return instance

    def __init__(self, name):
        self.name = name
        print("A __init__ be called")
        print("A init:",self)

a=A('aa')
print('a instance of name:',a.name)
print("_________________")

class B(type): # 构建类的类 B ，必须继承自type，且调用父类的__new__方法
    def __new__(cls, *args, **kwargs):
        print("B cls:", cls)
        print("B __new__ be called")
        instance = super().__new__(cls, cls.__name__, args, kwargs) # 产生一个新类
        print("B instance:", instance)
        return instance

    def __init__(self):
        self.someAttr = 'someAttr'
        print("B __init__ be called")
        print("B init",self)

b=B() #生成一个新类b 并且会调用 B.__init__

print('type of b', type(b))
print('009 b.someAttr', b.someAttr)
print("_________________")
bIns = b() # 因为新类b没有__init__等方法，所以没啥好调用的
print('010', type(bIns))
print('011', bIns.someAttr) # someAttr
bIns.someAttr = 'someAttr2'
print('012', bIns.someAttr) # someAttr2
print('013', b.someAttr) # someAttr
